package com.eureka.eurekaserviceinvoker;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 *
 * Created by earl on 2018/4/17.
 */
@Configuration
@RestController
@RequestMapping("/invoker")
public class InvokerController {


    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }


    @GetMapping("/router")
    public String person( ){
        RestTemplate restTemplate = getRestTemplate();
        //通过服务提供者的应用名称(eureka-service-provider项目的yml设置spring.application.name)调用接口
        String uri = "http://eureka-service-provider/provider/person/2?name=demoTest";
        return restTemplate.getForObject( uri, String.class);
    }


}
